import Ajax from './ajax';

var Request = {
  Tool:{
    tables(){
      return Ajax.get('/tool/tables');
    },
    routes(){
      return Ajax.get('/tool/routes');
    },
    columns(param){
      return Ajax.get('/tool/columns',param);
    },
    saveCols(param){
      return Ajax.post('/tool/colsOption',param);
    },
    getCols(param){
      return Ajax.get('/tool/colsOption',param);
    },
    generate(param){
      return Ajax.post('/tool/generate',param);
    }
  },
  Area: {
    index(param) {
      return Ajax.get('/collectCat/index',param);
    },
    store(param) {
      return Ajax.post('/collectCat/store',param);
    },
    delete(param) {
      return Ajax.post('/collectCat/delete',param);
    },
    dict() {
      return Ajax.get('/area/dict');
    },
  },
  Cate: {
    index(param) {
      return Ajax.get('/cate/index',param);
    },
    store(param) {
      return Ajax.post('/cate/store',param);
    },
    delete(param) {
      return Ajax.post('/cate/delete',param);
    },
    dict(param = {}) {
      return Ajax.get('/cate/dict',param);
    },
  },

  User: {
    info() {
      return Ajax.get('/account/info');
    }
  },
  Dict: {
    get() {
      return Ajax.get(`/dict`);
    }
  },
  Home: {
    getMessageList() {
      return Ajax.get(`/home/messages`);
    }
  },
  Account: {
    menus() {
    }
  },
  Login: {
    login(param) {
      return Ajax.post('/auth/login', param);
    },
    logout(param) {
      return Ajax.post('/auth/logout', param);
    }
  },
  Management: {
    users(params) {
      return Ajax.get('/management/users', params);
    },
    roles(params) {
      return Ajax.get('/management/roles', params);
    }
  }
};

//批量生产模板化路由
let tasks = ['areas'];


tasks.push('stores');
tasks.push('adminUsers');
tasks.push('adminRoles');
tasks.push('adminPermissions');
tasks.push('failedJobs');
tasks.push('collectCats');
tasks.push('platforms');
tasks.push('ads');
tasks.push('markets');
tasks.push('cates');
tasks.push('adminMenu');
tasks.push('areas');
tasks.push('tokens');
tasks.push('comments');
tasks.push('articleContent');
tasks.push('departments');
tasks.push('departmentJobs');
tasks.push('employees');
tasks.push('workflowTypes');
tasks.push('workflowTypeNodes');
tasks.push('workflowTypeNodeAuths');
tasks.push('errorLogs');
tasks.push('dicts');
//apiPushEnd


tasks.forEach((key)=>{
  Request[key] = {
    index(param) {
      return Ajax.get(`/${key}/index`,param);
    },
    store(param) {
      return Ajax.post(`/${key}/store`,param);
    },
    delete(param) {
      return Ajax.post(`/${key}/delete`,param);
    },
    dict(param = {}) {
      return Ajax.get(`/${key}/dict`,param);
    },
    ajax(path='index',method='get',param={}){
      if(method == 'get'){
        return Ajax.get(`/${key}/${path}`,param);
      }else{
        return Ajax.post(`/${key}/${path}`,param);
      }
    }
  }
});

export default Request;